#include <iostream>
#include "DSTHType.h"
#include "LBServer.h"
#include "LBClient.h"
#include "EventLoop.h"
#include "Log.h"
#include "Options.h"

using namespace dsth;
using namespace std;

#ifdef IS_WINDOWS
static void ExitForWindows() {
    cout << "::WSACleanup()" << endl;
    ::WSACleanup();
}
#endif

int main(int argc, char** argv) {
    NewLogger("./lb_server.log", Logger::E_DEBUG);
#ifdef IS_WINDOWS
    WSADATA wsaData;
    int err = ::WSAStartup( MAKEWORD(2,2), &wsaData );
    if( err != NO_ERROR )
        cout << "Error at WSAStartup" << endl;
    ::atexit(ExitForWindows);
#endif
    //SetOption("SelfConnectionEable", false);
    EventLoop loop;
    InetSocketAddress addr(atoi(argv[2]));
    InetSocketAddress buddy(argv[3], atoi(argv[4]));
    LBServer server(&loop, addr, buddy);
    //server.SetBuddyServerAdder("10.0.0.122", 10085);
    server.Run();
    //LBClient client(&loop, buddy, addr.ToHostPortFormat().c_str());
    //client.Run();
    loop.Loop();
    return 0;
}
